package homework;

import java.util.Arrays;

public class ProductTest {
    public static void main(String[] args) {
        Product[] arr = new Product[10];
        Product s = new Product(1, "矿泉水", 204, "上海");
        Product s1 = new Product(2, "面包", 238, "苏州");
        Product s2 = new Product(3, "泡面", 254, "上海");
        Product s3 = new Product(4, "奶茶", 336, "大庆");
        Product s4 = new Product(5, "红肠", 453, "哈尔滨");
        Product s5 = new Product(6, "蛋糕", 340, "齐齐哈尔");
        Product s6 = new Product(7, "牛肉干", 349, "内蒙古");
        Product s7 = new Product(8, "烤鸭", 673, "北京");
        Product s8 = new Product(9, "啤酒", 571, "山东");
        Product s9 = new Product(10, "酸奶", 220, "杭州");

        arr[0] = s;
        arr[1] = s1;
        arr[2] = s2;
        arr[3] = s3;
        arr[4] = s4;
        arr[5] = s5;
        arr[6] = s6;
        arr[7] = s7;
        arr[8] = s8;
        arr[9] = s9;

        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length; i++) {

            if (arr[i].getPrice() > 300) {

                System.out.println(arr[i].getName());


            }

        }
        sort01(arr);

    }
    public static void sort01(Product[] arr) {

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j].getPrice() > arr[j+1].getPrice()) {
                    Product m = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = m;
                }

            }

        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }
}


